<?php
//------- logistic wxapp -------
namespace api\logi\model;

use app\admin\model\RouteModel;
use think\Model;
use think\Db;

class LogiPostModel extends Model {

    protected $type = [
        'more' => 'array',
    ];

    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = true;

    /**
     * 关联 user表
     * @return $this
     */
    public function user() {
        return $this->belongsTo('UserModel', 'user_id')->setEagerlyType(1);
    }

    /**
     * 关联分类表
     */
    public function categories() {
        return $this->belongsToMany('LogiCategoryModel', 'logi_category_post', 'category_id', 'post_id');
    }

    /**
     * published_time 自动完成
     * @param $value
     * @return false|int
     */
    public function setPublishedTimeAttr($value) {
        return strtotime($value);
    }
}
